<?php 
/**
 *   Joomdiet - components/models/physicalactivity.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.model');

class JoomdietModelPhysicalActivity extends JModel
{
    var $_data;
    
    var $category_tag = array(
        'COM_JOOMDIET_BASIC_ACTIVITY',
        'COM_JOOMDIET_DIARY_LIFE_ACTIVITY',
        'COM_JOOMDIET_HOME_ACTIVITY',
        'COM_JOOMDIET_SPORT_ACTIVITY',
        'COM_JOOMDIET_JOB_ACTIVITY'
    );
    
    function __construct()
    {
        parent::__construct();
    }
    
    function setId($id)
    {
        $this->_id = $id;
        $this->_data = null;
    }
    
    function _buildQuery()
    {
        $query = 'SELECT * FROM #__joomdiet_Physical_Activity';
        return $query;
    }
    
    
    
    function getData()
    {
        if (empty($this->_data)) {
            $query = $this->_buildQuery();
            $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
        }
        
        return $this->_data;
    }
    
    function getAllData()
    {
        if (empty($this->_data)) {
            $query = $this->_buildQuery();
            $this->_data = $this->_getList($query);
        }
        
        return $this->_data;
    }
    
    function getModel()
    {
        return $this;
    }
    
    function getPhysicalActivity($id)
    {
        if (($id == null) or ($id == '')) {
            $query = 'SELECT * FROM #__joomdiet_Physical_Activity WHERE id=0';
        } else $query = 'SELECT * FROM #__joomdiet_Physical_Activity WHERE id='.$id;
        $this->_db->setQuery($query);
        $obj = $this->_db->loadObject();
        if ($obj == null) {
            $obj->id = 0;
            $obj->name = '';
            $obj->energy = '';
            $obj->category_tag = '';
        }
        return $obj;
    }
    
    function getPhysicalActivities($category_id)
    {
        $query = 'SELECT * FROM #__joomdiet_Physical_Activity WHERE category_tag='.$category_id;
        $this->_db->setQuery($query);
        return $this->_db->loadObjectList();
    }
}
?>

